<template>
<div>

	<myheader  />

	<Reply :data="mydata"  />


		<van-cell-group>

		<van-field label="分类id" v-model="fid" />

		<van-field label="分类名称" v-model="name" />

		<van-field label="分类参数" v-model="params" />

		<van-button color="blue" @click="addcate()">添加分类</van-button>

	</van-cell-group>


<<<<<<< HEAD
=======

>>>>>>> afcc523b004321adbe11ac83d9b5087146701336
</div>
</template>


<script>


//导入其他组件
import myheader from './myheader.vue';
import Reply from './Reply.vue';
import bus from './bus.js';


export default{

	//声明组件
	components:{

		'myheader':myheader,
		'Reply':Reply,
		
	},
	//构造方法
	created() {  

		//监听
		bus.$on('msg',target => {


			console.log(target);

			this.fid = target;


		});


}, 
	//声明变量
	data(){

		return {

			//数据
			mydata:{},
			fid:localStorage.getItem("fid"),
			name:"",
			params:""


		}


	},
	//自定义过滤器
	filters:{

			myfilter:function(value){


				value = value.slice(0,3);

				return value + "********";


			}

	},
	//初始化方法
	mounted(){

		this.get_data();


		
	},
	//声明方法
	methods:{

		getmsg:function(data){

			console.log(data);

			this.fid = data;

		},

		//添加分类
		addcate:function(){


			//发送请求
			this.axios.post(
				'http://localhost:5000/addcate/',
				this.qs.stringify({fid:this.fid,name:this.name,params:this.params})).then((result) =>{

					console.log(result);

					if(result.data.code==200){

						this.$toast.success('添加成功');

						this.get_data();

					}else{
						this.$toast.fail(result.data.msg);
					}

			});

		},
		//获取数据
		get_data:function(){


			//发送请求
			this.axios.get(
				'http://localhost:5000/catelist/').then((result) =>{

					console.log(result);

					// 声明根节点
					var mytree = {'id':0,name:""};

					mytree['children'] = result.data;

					this.mydata = mytree;

					console.log(this.mydata);


			});


		}
		


	}


}
	


</script>


<style>

ul {

	padding-left:10rem;
	list-style:none;

}

</style>